package chrisbode.cps142.a1;

public class Appointment {
	private String description;
	private TimeOfDay time;
	
	/**
	 * Created a midnight appointment with an empty description.
	 */
	public Appointment() {
		this("");
	}

	/**
	 * Creates a midnight appointment with the specified description.
	 * @param description
	 */
	public Appointment(String description) {
		this(description, new TimeOfDay());
	}
	
	/**
	 * Creates an appointment with the specified description at the specified time.
	 * @param description
	 * @param hours
	 * @param minutes
	 * @param seconds
	 */
	public Appointment(String description, int hours, int minutes, int seconds) {
		this(description, new TimeOfDay(hours, minutes, seconds));
	}
	
	/**
	 * Creates an appointment with the specified description at the time represented by the supplied TimeOfDay object.
	 * @param description
	 * @param time
	 */
	public Appointment(String description, TimeOfDay time) {
		this.description = description;
		this.time = time;
	}
	
	/**
	 * Creates an appointment that is a copy of the specified appointment.
	 * @param toCopy
	 */
	public Appointment(Appointment toCopy) {
		this.description = toCopy.description; // Strings are immutable, and have no clean clone or copy method.
		this.time = toCopy.time.copy();
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the time
	 */
	public TimeOfDay getTime() {
		return time.copy();
	}

	/**
	 * @param time the time to set
	 */
	public void setTime(TimeOfDay time) {
		this.time = time;
	}

	/**
	 * @param hours
	 * @param minutes
	 * @param seconds
	 * @see chrisbode.cps142.a1.TimeOfDay#setTime(int, int, int)
	 */
	public void setTime(int hours, int minutes, int seconds) {
		time.setTime(hours, minutes, seconds);
	}
	
	/**
	 * Returns a string that represents this appointment.
	 */
	public String toString() {
		return "At " + this.getTime().toString() + ", " + this.getDescription();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((time == null) ? 0 : time.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Appointment))
			return false;
		Appointment other = (Appointment) obj;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (time == null) {
			if (other.time != null)
				return false;
		} else if (!time.equals(other.time))
			return false;
		return true;
	}
	
	/**
	 * @return A deep copy of this appointment.
	 */
	public Appointment copy() {
		return new Appointment(this);
	}
}
